<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <a-form :form="form">
        <a-row>

          <a-col :xs="24" :sm="12">
            <a-form-item label="档案馆名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['dangAnGuanMingCheng']" placeholder="请输入档案馆名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="档案馆代码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['dangAnGuanDaiMa']" placeholder="请输入档案馆代码"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="全宗名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['quanZongMingCheng']" placeholder="请输入全宗名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="立档单位名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['liDangDnWeiMingCheng']" placeholder="请输入立档单位名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="档号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['dangHao']" placeholder="请输入档号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="全宗号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['quanZongHao']" placeholder="请输入全宗号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="目录号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['muLuHao']" placeholder="请输入目录号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="年度" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['nianDu']" placeholder="请输入年度"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="保管期限" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['baoCunQiXin']" placeholder="请输入保管期限"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="文档序号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wenDangXuHao']" placeholder="请输入文档序号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="页号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['yeHao']" placeholder="请输入页号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="内容描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['neiRongMiaoShu']" placeholder="请输入内容描述"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="题名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['tiMing']" placeholder="请输入题名"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="主题词" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zhuTiCi']" placeholder="请输入主题词"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="关键词" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['guanJianCi']" placeholder="请输入关键词"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="分类号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['fenLeiHao']" placeholder="请输入分类号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="文件编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wenJianBianHao']" placeholder="请输入文件编号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="责任者" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zeRenZhe']" placeholder="请输入责任者"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择日期" v-decorator="['riQi']" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="文种" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['wenZhong']" placeholder="请输入文种"></a-input>
            </a-form-item>
          </a-col>
          <!-- <a-col :xs="24" :sm="12">
            <a-form-item label="密级" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['miJi']" placeholder="请输入密级"></a-input>
            </a-form-item>
          </a-col> -->
          <a-col :xs="24" :sm="12">
            <a-form-item label="密级" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['miJi']" :trigger-change="true" dictCode="MiJi" placeholder="请选择密级"/>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="保密期限" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['baoMiQiXian']" placeholder="请输入保密期限"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="件数" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['jianShu']" placeholder="请输入件数"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="页数" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['yeShu']" placeholder="请输入页数"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item label="语种" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['yuZhong']" placeholder="请输入语种"></a-input>
            </a-form-item>
          </a-col>

        </a-row>
      </a-form>

      <!-- 子表单区域 -->
      <a-tabs v-model="activeKey" @change="handleChangeTabs">
        <a-tab-pane tab="文书子表" :key="refKeys[0]" :forceRender="true">
          <j-editable-table
            :ref="refKeys[0]"
            :loading="wsZiWenShuTable.loading"
            :columns="wsZiWenShuTable.columns"
            :dataSource="wsZiWenShuTable.dataSource"
            :maxHeight="300"
            :rowNumber="true"
            :rowSelection="true"
            :actionButton="true"/>
        </a-tab-pane>
        
        <a-tab-pane tab="文书正文" :key="refKeys[1]" :forceRender="true">
          <j-editable-table
            :ref="refKeys[1]"
            :loading="wsZhengWenTable.loading"
            :columns="wsZhengWenTable.columns"
            :dataSource="wsZhengWenTable.dataSource"
            :maxHeight="300"
            :rowNumber="true"
            :rowSelection="true"
            :actionButton="true"/>
        </a-tab-pane>
        
        <a-tab-pane tab="文书业务" :key="refKeys[2]" :forceRender="true">
          <j-editable-table
            :ref="refKeys[2]"
            :loading="wsYeWuTable.loading"
            :columns="wsYeWuTable.columns"
            :dataSource="wsYeWuTable.dataSource"
            :maxHeight="300"
            :rowNumber="true"
            :rowSelection="true"
            :actionButton="true"/>
        </a-tab-pane>
        
      </a-tabs>

    </a-spin>
  </j-modal>
</template>

<script>

  import pick from 'lodash.pick'
  import { FormTypes,getRefPromise } from '@/utils/JEditableTableUtil'
  import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  

  export default {
    name: 'WsZhuWenShuModal',
    mixins: [JEditableTableMixin],
    components: {
      JDate,
    },
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
        },
        refKeys: ['wsZiWenShu', 'wsZhengWen', 'wsYeWu', ],
        tableKeys:['wsZiWenShu', 'wsZhengWen', 'wsYeWu', ],
        activeKey: 'wsZiWenShu',
        // 文书子表
        wsZiWenShuTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '数字化属性',
              key: 'shuZiHuaShuXing',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '数字化对象形态',
              key: 'shuZiHuaDuiXiangXingTai',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '扫描分辨率',
              key: 'saoMiaoFenBianLv',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '扫描色彩模式',
              key: 'saoMiaoSeCaiMoShi',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '图像压缩方案',
              key: 'tuXiangYaSuoFangAn',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '电子签名',
              key: 'dianZiQianMing',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '签名规则',
              key: 'qianMingGuiZei',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '签名时间 ',
              key: 'qianMingShiJian',
              type: FormTypes.date,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '签名人',
              key: 'qianMingRen',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '签名结果',
              key: 'qianMingJieGuo',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '证书',
              key: 'zhengShu',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '证书引证',
              key: 'zhengShuYinZheng',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '签名算法标识',
              key: 'qianMingSuanFanBiaoShi',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '存储位置',
              key: 'cunChuWeiZhi',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '当前位置',
              key: 'dangQianWeiZhi',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '脱机载体编号',
              key: 'tuoJiZaiTiHangBiaoShi',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '脱机载体地址',
              key: 'tuoJiZaiTiDiZhi',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '缩微号',
              key: 'suoWeiHao',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
          ]
        },
        // 文书正文
        wsZhengWenTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '电子属性',
              key: 'dianZiShuXing',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '格式信息',
              key: 'geShiXinXi',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '计算机文件名',
              key: 'jiSuanJiWenJianMing',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '计算机文件大小',
              key: 'jiSuanJiWenJianDaXiao',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '文档创建程序',
              key: 'wenDnagChuangJianChengXu',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '信息系统描述',
              key: 'xinXiXiTongMiaoShu',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
          ]
        },
        // 文书业务
        wsYeWuTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '业务状态',
              key: 'yeWuZhuangTai',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '业务行为',
              key: 'yeWuXingWei',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '行为时间',
              key: 'xingWeiShiJian',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '行为依据',
              key: 'xingWeiYiJu',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '行为描述',
              key: 'xingWeiMiaoShu',
              type: FormTypes.input,
              width:"200px",
              placeholder: '请输入${title}',
              defaultValue: '',
            },
          ]
        },
        url: {
          add: "/org.jeecg.modules.gkak/wsZhuWenShu/add",
          edit: "/org.jeecg.modules.gkak/wsZhuWenShu/edit",
          wsZiWenShu: {
            list: '/org.jeecg.modules.gkak/wsZhuWenShu/queryWsZiWenShuByMainId'
          },
          wsZhengWen: {
            list: '/org.jeecg.modules.gkak/wsZhuWenShu/queryWsZhengWenByMainId'
          },
          wsYeWu: {
            list: '/org.jeecg.modules.gkak/wsZhuWenShu/queryWsYeWuByMainId'
          },
        }
      }
    },
    methods: {
      getAllTable() {
        let values = this.tableKeys.map(key => getRefPromise(this, key))
        return Promise.all(values)
      },
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter() {
        let fieldval = pick(this.model,'dangAnGuanMingCheng','dangAnGuanDaiMa','quanZongMingCheng','liDangDnWeiMingCheng','dangHao','quanZongHao','muLuHao','nianDu','baoCunQiXin','wenDangXuHao','yeHao','neiRongMiaoShu','tiMing','zhuTiCi','guanJianCi','fenLeiHao','wenJianBianHao','zeRenZhe','riQi','wenZhong','miJi','baoMiQiXian','jianShu','yeShu','yuZhong')
        this.$nextTick(() => {
          this.form.setFieldsValue(fieldval)
        })
        // 加载子表数据
        if (this.model.id) {
          let params = { id: this.model.id }
          this.requestSubTableData(this.url.wsZiWenShu.list, params, this.wsZiWenShuTable)
          this.requestSubTableData(this.url.wsZhengWen.list, params, this.wsZhengWenTable)
          this.requestSubTableData(this.url.wsYeWu.list, params, this.wsYeWuTable)
        }
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let main = Object.assign(this.model, allValues.formValue)
        return {
          ...main, // 展开
          wsZiWenShuList: allValues.tablesValue[0].values,
          wsZhengWenList: allValues.tablesValue[1].values,
          wsYeWuList: allValues.tablesValue[2].values,
        }
      },
      validateError(msg){
        this.$message.error(msg)
      },
     popupCallback(row){
       this.form.setFieldsValue(pick(row,'dangAnGuanMingCheng','dangAnGuanDaiMa','quanZongMingCheng','liDangDnWeiMingCheng','dangHao','quanZongHao','muLuHao','nianDu','baoCunQiXin','wenDangXuHao','yeHao','neiRongMiaoShu','tiMing','zhuTiCi','guanJianCi','fenLeiHao','wenJianBianHao','zeRenZhe','riQi','wenZhong','miJi','baoMiQiXian','jianShu','yeShu','yuZhong'))
     },

    }
  }
</script>

<style scoped>
</style>